<template>
  <van-nav-bar
      :title="title"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
  >
    <template #right>
      <van-icon name="search" size="18" />
    </template>
  </van-nav-bar>

  <router-view />

  <van-tabbar route>
    <van-tabbar-item replace to="/" icon="home-o" >首页</van-tabbar-item>
    <van-tabbar-item replace to="/classify" icon="gem-o">分类</van-tabbar-item>
    <van-tabbar-item replace to="/personal" icon="user-o">个人中心</van-tabbar-item>
  </van-tabbar>

</template>
<script>
import {ref,onMounted} from 'vue'
import { Toast } from 'vant';
import { useRouter } from 'vue-router'
import {hycloud} from './assets/api/requets'
import {getSgbItems,getHuaYu} from "@/assets/api/getSgbList"

export default {
  setup(){

    const vanNames = ref(['首页','分类','个人中心'])

    const title = ref('首页')

    const router = useRouter()

    let onClickLeft = ()=>{
      Toast('返回')
    }
    let onClickRight = ()=>{
      Toast('搜索')
    }

    router.afterEach((to)=>{

      title.value = to.meta.title

    })

    onMounted(()=>{


      // console.log("执行云函数");
      getSgbItems()
      .then(res=>{
        console.log(res);
      })
      .catch(err=>{
        console.log("发生错误=>",err);
      })

      hycloud().database({env: 'zhaohuaishuai-9bmq3'}).collection('dataPage').get().then(
          res=>{
            console.log(res);
          }
      );

      // getHuaYu()
      // .then(res=>{
      //   console.log(res);
      // })


    })


    return {
      title,
      onClickLeft,
      onClickRight,
      vanNames,
      getHuaYu

    }

  }
}
</script>
<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
